// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
/* jshint esversion: 6 */
window.getIps = "//api.mofing.com";

window.getIpwwws = "//www.mofing.com";

window.params = "?uid=439124&token=bb97f5884c72a98a9ade4063cc86e0da";

import Vue from 'vue';
import App from './App';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';
import qs from 'qs';
import VueQuillEditor from 'vue-quill-editor';
import VueDND from 'awe-dnd';
import VueChart from 'vue-chart-js';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
import 'babel-polyfill';
import 'es6-promise/auto';
import './assets/font/iconfont.css';
Vue.use(ElementUI);
Vue.use(VueDND);
Vue.use(VueQuillEditor);
Vue.use(VueChart);
Vue.filter("filterTimes", function(val) {
	let y = new Date(val).getFullYear();
	let m = new Date(val).getMonth() + 1 >= 10 ? new Date(val).getMonth() + 1 : '0' + (new Date(val).getMonth() + 1);
	let d = new Date(val).getDate() >= 10 ? new Date(val).getDate() : '0' + new Date(val).getDate();
	return y + "-" + m + "-" + d;
});
Vue.filter("filterTimess", function(val) {
	let y = new Date(val).getFullYear();
	let m = new Date(val).getMonth() + 1 >= 10 ? new Date(val).getMonth() + 1 : '0' + (new Date(val).getMonth() + 1);
	let d = new Date(val).getDate() >= 10 ? new Date(val).getDate() : '0' + new Date(val).getDate();
	let h = new Date(val).getHours() >= 10 ? new Date(val).getHours() : '0' + new Date(val).getHours();
	let ms = new Date(val).getMinutes() >= 10 ? new Date(val).getMinutes() : '0' + new Date(val).getMinutes();
	let s = new Date(val).getSeconds() >= 10 ? new Date(val).getSeconds() : '0' + new Date(val).getSeconds();
	return y + "-" + m + "-" + d + " " + h + ":" + ms + ":" + s;
});
Vue.filter("filterTimesss", function(val) {
	let y = new Date(val).getFullYear();
	let m = new Date(val).getMonth() + 1 >= 10 ? new Date(val).getMonth() + 1 : '0' + (new Date(val).getMonth() + 1);
	let d = new Date(val).getDate() >= 10 ? new Date(val).getDate() : '0' + new Date(val).getDate();
	let h = new Date(val).getHours() >= 10 ? new Date(val).getHours() : '0' + new Date(val).getHours();
	let ms = new Date(val).getMinutes() >= 10 ? new Date(val).getMinutes() : '0' + new Date(val).getMinutes();
	return y + "-" + m + "-" + d + " " + h + ":" + ms;
});
Vue.filter("moneyFormat",function(val){
	return typeof val === 'number' ? val.toFixed(2) : Number(val).toFixed(2);
});

//整数还是整数，小数保留2位小数（不四舍五入）
Vue.filter("twoDecimal",function(val){
	return Math.floor(val * 100) / 100;
});


Vue.config.productionTip = false;

function axiosPost(url, params, bool,type) {
	return new Promise((resolve, reject) => {
		axios({
			url: bool === true ? window.getIpwwws + url : window.getIps + url,
			method: 'post',
			headers: {
				'Content-Type': type || 'application/x-www-form-urlencoded;charset=UTF-8'
			},
			data: qs.stringify(params)
		}).then(res => {
			resolve(res.data);
		}).catch((error) => {
			reject(error);
		});
	});
}

function axiosGet(url, params, bool) {
	return new Promise((resolve, reject) => {
		axios({
			url: bool === true ? window.getIpwwws + url : window.getIps + url,
			method: 'get',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
			},
			params
		}).then(res => {
			resolve(res.data);
		}).catch((error) => {
			reject(error);
		});
	});
}

/*
 * 统一支付
 * type 订单类型 1-balance 2-Alipay 3-Wechat
 * orderid 订单id
 * ordertype 订单类型
 * money 金额，只在充值或者转账时候用到
 */
function payOrder(type,orderid,ordertype,money){
	return new Promise(function(resolve, reject) {
	   var obj = {};
	   obj.payment = type;
	   obj.ordertype = ordertype;
	   obj.appid = 10000;
	   obj.id = orderid;
	   obj.buyerid = '';
	   obj.money = money;
	   obj.paytype = 'native';	   
	   //支付接口,获取返回参数
	   axios({
			url: window.getIpwwws+'/payment/pays/create.json',
			method: 'post',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
			},
			data: qs.stringify(obj)
		}).then(res => {
			resolve(res.data);
		}).catch((error) => {
			reject(error);
		});	   	   
	});
}

Vue.prototype.$axiosPost = axiosPost; //全局axiosPost配置----------交互就用这个足够
Vue.prototype.$axiosGet = axiosGet; //
Vue.prototype.$payOrder = payOrder; //
Vue.prototype.goTop = function(val = 0) {	
	if(document.documentElement.scrollTop) {
		document.documentElement.scrollTop = val;
	} else {
		document.body.scrollTop = val;
	}
};

/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	components: {
		App
	},
	template: '<App/>'
});